package com.dingshi.security.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.dingshi.security.R;

public class BreakAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<String> list;
	private LayoutInflater inflater;
	public BreakAdapter(Context context,ArrayList<String> breakList) {
		this.context = context;
		this.list = breakList;
		inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}
	
	@Override
	public int getCount() {
		return list!=null?list.size():0;
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String title = list.get(position);
		ViewHolder holder = null;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.spinner_item, null);
			holder = new ViewHolder();
			holder.spinner_item = (TextView) convertView.findViewById(android.R.id.text1);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		updateData(holder, title);
		return convertView;
	}
	private void updateData(ViewHolder holder, String title) {
		holder.spinner_item.setText(title!=null?title:"未知设备");
	}
	static class ViewHolder {
		public TextView spinner_item;
	}
}
